<?php
/**
 * +--------------------------------------------------------+
 * @Created by PhpStorm.
 * @Category Article.php
 * @Depiction:
 * Author: hwy
 * Date: 2020/6/17  16:23
 * +--------------------------------------------------------+
 */

namespace App\Models;


use App\Exceptions\ResponseException;

class Article extends BaseModel
{
    protected $table = "article";

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'id',
        'cid',
        'name',
        'content_md',
        'content_html',
        'describe',
        'status',
        'order',
        'created_at',
        'updated_at',
        'deleted_at',
        'file_id',
    ];

    public function has_one_category()
    {
        return $this->hasOne(Category::class, 'id', 'cid');
    }

    public function has_one_image()
    {
        return $this->hasOne(File::class, 'id', 'file_id');
    }

    //与标签多对多关联
    public function tags()
    {
        return $this->belongsToMany(Tag::class,'article_tag','article_id','tag_id');
    }


}
